<?php
    
    $stt = MyFunctionCustom::getStatusBooking($model->status);
?>
<div class="page-content">
    <div class="row-fluid">
        <div class="span12">
            <div class="row-fluid">
                <div class="widget-box">
                    <div class="widget-header widget-header-flat">
                        <h4 class="smaller red"><?php echo MyFunctionCustom::getInfoEvent($model->event_id,2); ?></h4>

                        <div class="widget-toolbar">
                            <label>
                                <small class="green">
                                    <?php if($model->status==STATUS_PENDING) : ?>
                                        <b class="red"><?php echo $stt; ?></b>
                                    <?php elseif($model->status == STATUS_DELIVER): ?>
                                        <b class="blue"><?php echo $stt; ?></b>
                                    <?php else: ?>
                                        <b class="green"><?php echo $stt; ?></b>
                                    <?php endif; ?>
                                </small>
                                <span class="lbl"></span>
                            </label>
                        </div>
                    </div>

                    <div class="widget-body">
                        <div class="widget-main">
                            <dl id="dt-list-1" class="dl-horizontal">
                                <dt>Ticket Order Number</dt>
                                <dd><b class="green"><?php echo $model->ticket_order_number; ?></b></dd>
                                
                                <dt></dt>
                                <dd style="margin-left:0px !important;">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th>Ticket Code</th>
                                                <th>Ticket Description</th>
                                                <th>Quantity</th>
                                                <th width="50">Remain Quantity</th>
                                                <th>Price per ticket</th>
                                                <th>Price of each ticket code</th>
                                                <th>Seat</th>
                                            </tr>
                                            
                                        </thead> 
                                        <tbody>
                                            <?php foreach($model->booked_details as $value) : ?>
                                            <?php $ticket_code = Ticket::model()->findByPk($value->ticket_id); ?>
                                            <tr>
                                                <td>
                                                    <?php echo $ticket_code->ticket_code;?> 
                                                </td>
                                                <td><?php echo $ticket_code->description_of_ticket; ?></td>
                                                <td>
                                                    <b class="blue">
                                                        <?php echo $value->quantity; ?>
                                                    </b>
                                                </td>
                                                <td>
                                                    <?php $real_quantity = MyFunctionCustom::remain_quantity(null,$ticket_code->temp_quantity,$ticket_code->remain_quantity); ?>
                                                    <?php if ($real_quantity < 10) : ?>
                                                        <b class="red">
                                                            <?php echo $real_quantity;  ?>
                                                        </b>
                                                    <?php else : ?>
                                                        <b class="blue"><?php echo $real_quantity; ?></b>
                                                    <?php endif; ?>
                                                </td>
                                                <td><b class="red"><?php echo number_format($ticket_code->price); ?> VND / 1 Ticket</b></td>
                                                <td><b class="green"><?php echo number_format($value->total_price); ?> VND</b></td>
                                                <td>
                                                    <?php if($value->seat != null) : ?>
                                                    <b class="blue">
                                                        <?php
                                                            $seat = CJSON::decode($value->seat);
                                                            foreach ($seat as $key => $value) {
                                                                echo $value . " ";
                                                            } 
                                                        ?>
                                                    </b>
                                                    <?php endif;?>
                                                </td>
                                            </tr>
                                        
                                            <?php endforeach;?>
                                        </tbody>
                                    
                                    </table>
                                </dd>
                                <dt>Percentage</dt>
                                <dd><b class="red"><?php if($model->percentage != null ) {echo $model->percentage; }else {echo "0";} ?>%</b></dd>
                                <dt>Total Price</dt>
                                <dd><b class="red"><?php echo number_format($model->total_price); ?> VND </b></dd>
                                <dt>Price Percentage</dt>
                                <dd><b class="red"><?php echo number_format(MyFunctionCustom::percentage_detail($model->total_price,$model->percentage)); ?> VND </b></dd>
                                <dt>End Price</dt>
                                <dd><b class="red"><?php echo number_format(MyFunctionCustom::percentage_calculate($model->total_price,$model->percentage)); ?> VND</b></dd>
                                <?php if ($model->percentage_reason != null) : ?>
                                    <dt>Percentage Reason</dt>
                                    <dd><b><?php echo $model->percentage_reason; ?></b></dd>   
                                <?php endif;?>
                                
                                
                                <dt>Status</dt>
                                <dd>                    
                                    <?php if($model->status==STATUS_PENDING) : ?>
                                        <b class="red"><?php echo $stt; ?></b>
                                    <?php elseif($model->status == STATUS_DELIVER): ?>
                                        <b class="green"><?php echo $stt; ?></b>
                                    <?php else: ?>
                                        <b class="blue"><?php echo $stt; ?></b>
                                    <?php endif; ?>
                                </dd>
                                <dt>Booked Date</dt>
                                <dd><?php echo date("d-M-Y",strtotime($model->booked_time)); ?></dd>
                                
                                <dt>Booked time</dt>
                                <dd><?php echo date("H:i",strtotime($model->booked_time)); ?></dd>
                                <dt>Customer Name</dt>
                                <dd><b class="red"><?php echo $model->user->first_name . ' ' . $model->user->last_name; ?></b></dd>
                                <dt>Facebook Email</dt>
                                <dd><b class="green"><?php echo $model->user->email; ?></b></dd>
                                <dt>Contact Email</dt>
                                <dd><b class="green"><?php echo $model->email_contact; ?></b></dd>
                                <dt>Phone</dt>
                                <dd>0<?php echo $model->phone; ?></dd>
                                <dt>Payment Type</dt>
                                <dd><b class="green"><?php echo MyFunctionCustom::getPayment($model->payment_type); ?></b></dd>
                                
                                <dt>Payment Address</dt>
                                <dd><?php echo $model->payment_address; ?></dd>

                                <dt>Delivery Address</dt>
                                <dd><?php echo $model->deliver_address; ?></dd>

                                
                                <dt>Deliver Process By User</dt>
                                <?php 
                                    $user_deliver = MyFunctionCustom::get_user_info($model->deliver_user_edit); 
                                    $user_finish = MyFunctionCustom::get_user_info($model->finish_user_edit); 
                                ?>
                                <dd><b class="green"><?php $dl_u = (isset($user_deliver)) ? $user_deliver->first_name . $user_deliver->last_name : "Not Available"; echo $dl_u; ?></b></dd>
                                <dt>Time / Date </dt>
                                <dd><b><?php $dl_t = (isset($model->deliver_edit_time)) ? date("h:i / d-M-Y",strtotime($model->deliver_edit_time)) : "Not Available"; echo $dl_t; ?></b></dd>
                                <dt>Finish Process By User</dt>
                                <dd><b class="green"><?php $fn_u = (isset($user_finish)) ? $user_finish->first_name . $user_finish->last_name : "Not Available";echo $fn_u; ?></b></dd>
                                <dt>Time / Date </dt>
                                <dd><b><?php $dl_t = (isset($model->finish_edit_time)) ? date("h:i / d-M-Y",strtotime($model->finish_edit_time)) : "Not Available"; echo $dl_t; ?></b></dd>
                                <dt>Additional Notes</dt>
                                <dd><?php echo $model->additional_note; ?></dd>
                                    <?php 
                                        $seat_map = Ticket::model()->findByAttributes(array('event_id' => $model->event_id,'seat_map' => 1)); 
                                        // var_dump($seat_map->pic_seat_map);die();
                                        if ($seat_map['pic_seat_map'] != null) :
                                    ?>
                                        <dt></dt>
                                        <dd style="margin-left:0px !important;">
                                            <img src='<?php echo Yii::app()->baseUrl . "/timthumb.php?src=" . Yii::app()->baseUrl . "/data/pic/" . $seat_map->pic_seat_map . "&w=750"; ?>' /></dd>
                                    <?php endif; ?>
                            </dl>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
